package cn.edu.hbwe.book.dao.impl;

import java.sql.Connection;

import java.sql.SQLException;

import javax.sql.DataSource;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import cn.edu.hbwe.book.dao.UserDao;
import cn.edu.hbwe.book.entity.User;
import cn.edu.hbwe.book.utils.DBCPUtil;
import cn.edu.hbwe.book.utils.DuridUtil;

public class UserDaoImpl implements UserDao{
	public  void addUser(User user)  {
		QueryRunner qr=new QueryRunner();
			try {
				String sql = "insert into user(username,password,gender,email,telephone,introduce) values(?,?,?,?,?,?)";
				Connection conn=DuridUtil.getConn();
				qr.update(conn, sql,user.getUsername(),user.getPassword(),user.getGender(),user.getEmail(),user.getTelephone(),user.getIntroduce());//数据自己补
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		
		
		
			
			
		
	}
	public User findUserByUsernameAndPassword(String username, String password)  {
		User user=null;
		QueryRunner runner=new QueryRunner();
		String sql="select * from user where username=? and password=?";
		Connection conn=DuridUtil.getConn();
		
		try {
			user = runner.query(conn, sql, new BeanHandler<User>(User.class),username,password);
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return user;
	}
	
	public void updateUserMessage(int id, String parameter, String parameter3) {
		QueryRunner qr=new QueryRunner();
		try {
			String sql="update user set password=?,telephone=? where id=?";
	
			Connection conn=DuridUtil.getConn();
			qr.update(conn, sql,parameter,parameter3,id);//数据自己补
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}
